package com.nulldev.util.math;

public class FrequencyUtil {

	// Hz
	
	public static final long MINIMUM = 0;
	
	/**
	 * Limit in Hz: 24000000 Hz <br>
	 * Limit in kHz: 24000 kHz <br>
	 * Limit in MHz: 24 MHz <br>
	 * Limit in GHz: 0.024 GHz <br>
	 */
	public static final long RTL_SDR_MINIMUM = 24000000L;
	/**
	 * Limit in Hz: 24000000 Hz <br>
	 * Limit in kHz: 24000 kHz <br>
	 * Limit in MHz: 24 MHz <br>
	 * Limit in GHz: 0.024 GHz <br>
	 */
	public static final lNumber RTL_SDR_MINIMUMl = lNumber.fromLong(RTL_SDR_MINIMUM);
	
	/**
	 * Limit in Hz: 64000000 Hz <br>
	 * Limit in kHz: 64000 kHz <br>
	 * Limit in MHz: 64 MHz <br>
	 * Limit in GHz: 0.064 GHz <br>
	 */
	public static final long E4000_SDR_MINIMUM = 64000000L;
	/**
	 * Limit in Hz: 64000000 Hz <br>
	 * Limit in kHz: 64000 kHz <br>
	 * Limit in MHz: 64 MHz <br>
	 * Limit in GHz: 0.064 GHz <br>
	 */
	public static final lNumber E4000_SDR_MINIMUMl = lNumber.fromLong(E4000_SDR_MINIMUM);
	
	public static final lNumber MINIMUMl = lNumber.fromLong(MINIMUM);
	/**
	 * Limit in Hz: 9999308000 Hz <br>
	 * Limit in kHz: 9999308 kHz <br>
	 * Limit in MHz: 9999.308 MHz <br>
	 * Limit in GHz: 9.999(.)308 GHz <br>
	 */
	public static final long SDR_MAX = 9999308000L;
	/**
	 * Limit in Hz: 9999308000 Hz <br>
	 * Limit in kHz: 9999308 kHz <br>
	 * Limit in MHz: 9999.308 MHz <br>
	 * Limit in GHz: 9.999(.)308 GHz <br>
	 */
	public static final lNumber SDR_MAXl = lNumber.fromLong(SDR_MAX);
	
	/**
	 * Limit in Hz: 1736000000 Hz <br>
	 * Limit in kHz: 1736000 kHz <br>
	 * Limit in MHz: 1736 MHz <br>
	 * Limit in GHz: 1.736 GHz <br>
	 */
	public static final long RTL_SDR_MAX = 1736000000L;
	
	/**
	 * Limit in Hz: 1736000000 Hz <br>
	 * Limit in kHz: 1736000 kHz <br>
	 * Limit in MHz: 1736 MHz <br>
	 * Limit in GHz: 1.736 GHz <br>
	 */
	public static final lNumber RTL_SDR_MAXl = lNumber.fromLong(RTL_SDR_MAX);
	
	/**
	 * Limit in Hz: 2300000000 Hz <br>
	 * Limit in kHz: 2300000 kHz <br>
	 * Limit in MHz: 2300 MHz <br>
	 * Limit in GHz: 2.3 GHz <br>
	 */
	public static final long E4000_SDR_MAX = 2300000000L;
	
	/**
	 * Limit in Hz: 2300000000 Hz <br>
	 * Limit in kHz: 2300000 kHz <br>
	 * Limit in MHz: 2300 MHz <br>
	 * Limit in GHz: 2.3 GHz <br>
	 */
	public static final lNumber E4000_SDR_MAXl = lNumber.fromLong(E4000_SDR_MAX);
	
	/**
	 * Limit in Hz: 1000 Hz <br>
	 * Limit in kHz: 1 kHz <br>
	 * Limit in MHz: 0.001 MHz <br>
	 * Limit in GHz: 0.000001 GHz <br>
	 */
	public static final long nSDR_MINIMUM = 1000L;
	/**
	 * Limit in Hz: 1000 Hz <br>
	 * Limit in kHz: 1 kHz <br>
	 * Limit in MHz: 0.001 MHz <br>
	 * Limit in GHz: 0.000001 GHz <br>
	 */
	public static final lNumber nSDR_MINIMUMl = lNumber.fromLong(nSDR_MINIMUM);
	
	/**
	 * Limit in Hz: 45000000 Hz <br>
	 * Limit in kHz: 45000 kHz <br>
	 * Limit in MHz: 45 MHz <br>
	 * Limit in GHz: 0.045 GHz <br>
	 */
	public static final long nSDR_MAXMIMUM = 45000000L;
	/**
	 * Limit in Hz: 45000000 Hz <br>
	 * Limit in kHz: 45000 kHz <br>
	 * Limit in MHz: 45 MHz <br>
	 * Limit in GHz: 0.045 GHz <br>
	 */
	public static final lNumber nSDR_MAXMIMUMl = lNumber.fromLong(nSDR_MINIMUM);
	
	public static boolean canTune(final long hz) {
		if (hz > MINIMUM && hz < SDR_MAX) {
			return true;
		}
		return false;
	}
	
	public static boolean canTune(final lNumber hz) {
		if (hz.moreThanZero() && hz.lessThan(SDR_MAX)) {
			return true;
		}
		return false;
	}
	
	public static boolean canTuneRTL(final long hz) {
		if (hz > RTL_SDR_MINIMUM && hz < RTL_SDR_MAX) {
			return true;
		}
		return false;
	}
	
	public static boolean canTuneRTL(final lNumber hz) {
		if (hz.moreThan(RTL_SDR_MINIMUM) && hz.lessThan(RTL_SDR_MAX)) {
			return true;
		}
		return false;
	}
	
	public static boolean canTuneE4000(final long hz) {
		if (hz > E4000_SDR_MINIMUM && hz < E4000_SDR_MAX) {
			return true;
		}
		return false;
	}
	
	public static boolean canTuneE4000(final lNumber hz) {
		if (hz.moreThan(E4000_SDR_MINIMUM) && hz.lessThan(E4000_SDR_MAX)) {
			return true;
		}
		return false;
	}
	
	public static boolean canTuneNSDR(final long hz) {
		if (hz > nSDR_MINIMUM && hz < nSDR_MAXMIMUM) {
			return true;
		}
		return false;
	}
	
	public static boolean canTuneNSDR(final lNumber hz) {
		if (hz.moreThan(nSDR_MINIMUM) && hz.lessThan(nSDR_MAXMIMUM)) {
			return true;
		}
		return false;
	}
	
	// Hz -> ?Hz
	
	public static long HzToKHz(final long hz) {
		return hz * 1000;
	}
	
	public static lNumber HzToKHz(final lNumber hz) {
		return hz.multiply(1000);
	}
	
	public static long HzToMHz(final long hz) {
		return hz * 1000 * 1000;
	}
	
	public static lNumber HzToMHz(final lNumber hz) {
		return hz.multiply(1000).multiply(1000);
	}
	
	public static long HzToGHz(final long hz) {
		return hz * 1000 * 1000 * 1000;
	}
	
	public static lNumber HzToGHz(final lNumber hz) {
		return hz.multiply(1000).multiply(1000).multiply(1000);
	}
}
